home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / mtz / (Misc) / GDEF projs / gdef2test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-15  |  3.3 KB  |  137 lines  |  [TEXT/KAHL]

  1. #include <GestaltEQu.h>
  2.  
  3. ProcPtr oldSAVRProc;
  4. Handle    savrHandle;
  5. Handle    savrDumHandle;
  6. ProcPtr oldASHIProc;
  7. Handle    ASHIHandle;
  8. Handle    ASHIDumHandle;
  9.  
  10. void ReplaceASHI(){
  11.     ProcPtr    tempProc;
  12.     OSErr    myErr;
  13.     long    response;
  14.     
  15.     /* if a selector was in place when ARASHI started, replace it                    */
  16.     if(ASHIHandle && oldASHIProc){
  17.         if(myErr = ReplaceGestalt('ASHI',(ProcPtr)oldASHIProc, &tempProc))
  18.                 Alert(133,0);
  19.     }
  20.     /* else install a dummy selector, or better remove it altogether if possible    */
  21.     /* not possible yet, so replace it with the dummy one #131                        */
  22.     else{
  23.         if(ASHIDumHandle = GetResource('GDEF',131)){
  24.             DetachResource(ASHIDumHandle);
  25.             if(ReplaceGestalt('SAVR', (ProcPtr)*ASHIDumHandle, &oldSAVRProc)){
  26.                 DisposHandle(ASHIDumHandle);
  27.                 ASHIDumHandle = 0L;
  28.                 Alert(133,0);
  29.             }
  30.         }
  31.     }
  32.     DisposHandle(ASHIHandle);
  33. }
  34.  
  35. /* ResetGestalt() will reset the Gestalt selectors to the way they were before         */
  36. /* starting.                                                                        */
  37. void ResetGestalt(){
  38.     ProcPtr    tempProc;
  39.     OSErr    myErr;
  40.     long    response;
  41.     
  42.     if(Gestalt('SAVR',&response))
  43.         SysBeep(1);
  44.     if(response == 0x12)
  45.         SysBeep(1);
  46.     /* if a selector was in place when ARASHI started, replace it                    */
  47.     if(savrHandle && oldSAVRProc){
  48.         if(myErr = ReplaceGestalt('SAVR',(ProcPtr)oldSAVRProc, &tempProc))
  49.                 Alert(130,0);
  50.     }
  51.     /* else install a dummy selector, or better remove it altogether if possible    */
  52.     /* not possible yet, so replace it with the dummy one #129                        */
  53.     else{
  54.         if(savrDumHandle = GetResource('GDEF',129)){
  55.             DetachResource(savrDumHandle);
  56.             if(ReplaceGestalt('SAVR', (ProcPtr)*savrDumHandle, &oldSAVRProc)){
  57.                 DisposHandle(savrDumHandle);
  58.                 savrDumHandle = 0L;
  59.                 Alert(133,0);
  60.             }
  61.         }
  62.     }
  63.     if(Gestalt('SAVR',&response))
  64.         SysBeep(1);
  65.     if(response == 0)
  66.         SysBeep(1);
  67.     DisposHandle(savrHandle);
  68.     if(Gestalt('SAVR',&response))
  69.         SysBeep(1);
  70.     if(response == 0)
  71.         SysBeep(1);
  72. }
  73.  
  74. int installASHI()
  75. {
  76.     
  77.     int    error = 0;
  78.     long    response;
  79.     OSErr    myErr;
  80.     OSErr     myNewErr = 0;
  81.     OSErr     myReplaceErr = 0;
  82.     
  83.     myErr = Gestalt('ASHI',&response);
  84.     if( (myErr == 0) && (response == 1)){  /* only one copy at a time please.. */
  85.         Alert(131,0);
  86.         return 1;
  87.     }
  88.     else{
  89.         oldASHIProc = 0L;                        /* mark none installed so far */
  90.         if(ASHIHandle = GetResource('GDEF',130)){
  91.             DetachResource(ASHIHandle);
  92.             if(myNewErr = NewGestalt('ASHI',*ASHIHandle))
  93.                 if(myReplaceErr = ReplaceGestalt('ASHI', *ASHIHandle, &oldASHIProc)){
  94.                     DisposHandle(ASHIHandle);
  95.                     ASHIHandle = 0L;
  96.                     Alert(132,0);
  97.                     error = 1;
  98.                 }
  99.         }
  100.     }
  101.     return error;
  102. }
  103.  
  104.  
  105. /* DisableSuperclock will set the Gestalt selector 'savr'     */
  106. /* to indicate that a screen saver, such as afterdark,         */
  107. /* is enabled already, thus superclock will                    */
  108. /* not attempt to draw on the playing surface.                */
  109. void DisableSuperClock(){
  110.     
  111.     long    response = 0;
  112.     OSErr     myNewErr = 0;
  113.     OSErr     myReplaceErr = 0;
  114.     
  115.     oldSAVRProc = 0L;
  116.     if(savrHandle = GetResource('GDEF',128)){
  117.         DetachResource(savrHandle);
  118.         if(myNewErr = NewGestalt('SAVR',(ProcPtr)(*savrHandle) ))
  119.             if(myReplaceErr = ReplaceGestalt('SAVR',(ProcPtr)(*savrHandle), &oldSAVRProc)){
  120.                 DisposHandle(savrHandle);
  121.                 savrHandle = 0L;
  122.                 Alert(129,0);
  123.             }
  124.     }
  125.     if(Gestalt('SAVR',&response))
  126.         SysBeep(1);
  127.     if(response == 0x12)
  128.         SysBeep(1);
  129. }
  130.  
  131. void main()
  132. {
  133.     installASHI();
  134.     DisableSuperClock();
  135.     ResetGestalt();
  136.     ReplaceASHI();
  137. }